import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:相差不过k的最多数
 * User: wangxin
 * Date: 2024-10-06
 * Time: 21:03
 */
public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        int n = in.nextInt();
        int k = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int l = 0,r = 0;
        int ans  = 0;
        while(r < n){
            if((arr[r] - arr[l]) > k){
                l++;
            }
            ans = Math.max(ans,r-l+1);
            r++;
        }
        System.out.println(ans);

    }
}
